// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Store from "./store"

// import ElementUI from 'element-ui';
import "./utils/element.js"
import 'element-ui/lib/theme-chalk/index.css';


Vue.config.productionTip = false
// 文件：main.js
import VueQuillEditor from 'vue-quill-editor'
// require styles 引入样式
// 下面三行必须要写
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.use(VueQuillEditor)

// Vue.use(ElementUI);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  Store,
  components: { App },
  template: '<App/>'
})

// // 全局过滤器
// Vue.filter('formDate', function (originVal) {
//   const dt = new Date(originVal * 1000)
//   const y = dt.getFullYear()
//   const m = (dt.getMonth() + 1 + '').padStart(2, '0')
//   const d = (dt.getDate() + '').padStart(2, '0')
//   const hh = (dt.getHours() + '').padStart(2, '0')
//   const mm = (dt.getMinutes() + '').padStart(2, '0')
//   const ss = (dt.getSeconds() + '').padStart(2, '0')

//   return `${y}-${m}-${d}/${hh}:${mm}:${ss} `
//   // ${hh}:${mm}:${ss}
// })

/**
 * 时间格式化
 */
Date.prototype.format = function (fmt = 'yyyy-MM-dd HH:mm:ss') {
  /**
   * 日期数据
   */
  const opts = {
    'y+': this.getFullYear().toString(),
    'M+': (this.getMonth() + 1).toString(),
    'd+': this.getDate().toString(),
    'H+': this.getHours().toString(),
    'm+': this.getMinutes().toString(),
    's+': this.getSeconds().toString(),
    'f+': this.getMilliseconds().toString()
  }
  for (const key in opts) {
    const value = opts[key];  //时间值
    if (new RegExp(`(${key})`).test(fmt)) {
      const result = RegExp.$1; //如果匹配成功则可以获取到结果
      fmt = fmt.replace(result, value.padStart(result.length, '0'));
    }
  }
  return fmt;
} 

// 全局路由构子 用户登录权限判断
router.beforeEach((to,from,next)=>{
  document.title=`${to.meta.title}`

  const role=localStorage.getItem("admin")
  const val=JSON.parse(role)
  if(val!==null){
    // console.log(val);
    const timeSpan=Date.now()-val.time;
    if(timeSpan>val.expire){
      localStorage.removeItem("admin")
      next("/login")
      return null
    }
  }
  if(!val&& to.path!=="/login"){
    next("login")
  }else if(to.meta.permission){
    val.value==="admin"?next():next("/403")
  }else{
     if(navigator.userAgent.indexOf("MISE")>-1&&to.path==="/edit"){
      alert("不支持")
     }else{
      next()
     }
  }
  next();
})